﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;


namespace MapAndCharacter_Filip
{
    public partial class Character_Creator : Form
    {
        TheCatalog theCatalog;

        string[] levelString;

        const int strIndex = 0;
        const int dexIndex = 1;
        const int conIndex = 2;
        const int intIndex = 3;
        const int wisIndex = 4;
        const int charIndex = 5;

        const int fortSaveIndex = 0;
        const int refSaveIndex = 1;
        const int willSaveIndex = 2;

        public Character_Creator()
        {
            InitializeComponent();

            levelString = new string[20] {"FIRST","SECOND","THIRD", "FOURTH", "FIFTH", "SIXTH", "SEVENTH", "EIGHTH", "NINTH", "TENTH", "ELEVENTH", "TWELEFTH", "THIRTEENTH", "FOURTEENTH", "FIFTEENTH", "SIXTEENTH", "SEVENTEENTH", "EIGHTEENTH","NINETEENTH", "TWENTITH"};
        }

        private void CharacterCreationMainForm_Load(object sender, EventArgs e)
        {
            XmlDocument doc = new XmlDocument();
            string startupPath = Path.Combine(Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).Parent.Parent.FullName, "Natural_20.xml");
            doc.Load(startupPath);
            XmlNodeList raceNodes = doc.DocumentElement.SelectNodes("/PATHFINDER/COREBOOK/RACES/RACE");
            XmlNodeList classNode = doc.DocumentElement.SelectNodes("/PATHFINDER/COREBOOK/CLASSES/CLASS");
            XmlNodeList baseAttackNode = doc.DocumentElement.SelectNodes("/PATHFINDER/COREBOOK/CLASSES/BASEATTACKS");
            XmlNodeList spellsNode = doc.DocumentElement.SelectNodes("/PATHFINDER/COREBOOK/SPELLS/SPELL");
            XmlNodeList featsNode = doc.DocumentElement.SelectNodes("/PATHFINDER/COREBOOK/FEATS/FEAT");

            theCatalog = new TheCatalog(raceNodes.Count, classNode.Count, spellsNode.Count, featsNode.Count);

            createRaces(raceNodes);

            createFeats(featsNode);



            createClasses(classNode, baseAttackNode);

            createSpells(spellsNode);

            
                
        }

        private void racesCB_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox tempCMB = (ComboBox)sender;

            string currentRaceName;

            if(tempCMB.Text != null)
                currentRaceName = tempCMB.Text;
            else
                return;



            descriptionTB.Text = theCatalog.racesD[currentRaceName].raceDescription;

            racialTraitsTB.Text = theCatalog.racesD[currentRaceName].raceRacialTraits;

            raceOVLB.Text = "Races: " + theCatalog.racesD[currentRaceName].raceName;

            if (theCatalog.racesD[currentRaceName].raceAnyAttribute)
                chooseAttributeBT.Enabled = true;
            else
                chooseAttributeBT.Enabled = false;
            
            
            strNumUD.Value += theCatalog.racesD[currentRaceName].raceAttributes[strIndex];
            strOVLB.Text = strNumUD.Value.ToString();
            int strTemp = (int)((strNumUD.Value - 10) / 2);
            if (strTemp >= 0)
                lblStrMod.Text = lblStrModOV.Text = "+" + strTemp.ToString();
            else
                lblStrMod.Text = lblStrModOV.Text = strTemp.ToString();

            strNumUD.Value = 10;
            dexNumUD.Value = 10;
            conNumUD.Value = 10;
            intNumUD.Value = 10;
            wisNumUD.Value = 10;
            charNumUD.Value = 10;
            
            strNumUD.Value = strNumUD.Value + theCatalog.racesD[currentRaceName].raceAttributes[strIndex];
            dexNumUD.Value = dexNumUD.Value + theCatalog.racesD[currentRaceName].raceAttributes[dexIndex];
            conNumUD.Value = conNumUD.Value + theCatalog.racesD[currentRaceName].raceAttributes[conIndex];
            intNumUD.Value = intNumUD.Value + theCatalog.racesD[currentRaceName].raceAttributes[intIndex];
            wisNumUD.Value = wisNumUD.Value + theCatalog.racesD[currentRaceName].raceAttributes[wisIndex];
            charNumUD.Value = charNumUD.Value + theCatalog.racesD[currentRaceName].raceAttributes[charIndex];

            strOVLB.Text = strNumUD.Value.ToString();
            dexOVLB.Text = dexNumUD.Value.ToString();
            conOVLB.Text = conNumUD.Value.ToString();
            intOVLB.Text = intNumUD.Value.ToString();
            wisOVLB.Text = wisNumUD.Value.ToString();
            charOVLB.Text = charNumUD.Value.ToString();

            lblPointsLeftNum.Text = "0";
            cbPointFantasy.Text = "";
            lblPointsFantasy.Text = "Points : 0";
        
        }

        private void chooseAttributeBT_Click(object sender, EventArgs e)
        {
            ChooseAttributeForm chooseAttribueForm = new ChooseAttributeForm();

            var result = chooseAttribueForm.ShowDialog();
            
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                if (chooseAttribueForm.attribute == 0)
                {
                    strOVLB.Text = (strNumUD.Value + 2).ToString();
                    strNumUD.Value += 2;
                    int strTemp = (int)((strNumUD.Value - 10) / 2);
                    if (strTemp >= 0)
                        lblStrMod.Text = lblStrModOV.Text = "+" + strTemp.ToString();
                    else
                        lblStrMod.Text = lblStrModOV.Text = strTemp.ToString();
                }
                else if (chooseAttribueForm.attribute == 1)
                    dexOVLB.Text = (dexNumUD.Value + 2).ToString();
                else if (chooseAttribueForm.attribute == 2)
                    conOVLB.Text = (conNumUD.Value + 2).ToString();
                else if (chooseAttribueForm.attribute == 3)
                    intOVLB.Text = (conNumUD.Value + 2).ToString();
                else if (chooseAttribueForm.attribute == 4)
                    wisOVLB.Text = (wisNumUD.Value + 2).ToString();
                else if (chooseAttribueForm.attribute == 5)
                    charOVLB.Text = (charNumUD.Value + 2).ToString();

            }
        }

        private void createRaces(XmlNodeList racesNode)
        {
            for (int i = 0; i < racesNode.Count; i++)
            {

                string currentName = racesNode[i]["NAME"].InnerText;

                theCatalog.addNewRace(currentName);

                theCatalog.racesD[currentName].raceName = racesNode[i]["NAME"].InnerText;
                theCatalog.racesD[currentName].raceDescription = racesNode[i]["DESCRIPTION"].InnerText;
                theCatalog.racesD[currentName].raceRacialTraits = racesNode[i]["RACIALTRAITS"].InnerText;

                if (racesNode[i]["MODIFIERS"].Attributes["any"].Value.Equals("false"))
                {

                    theCatalog.racesD[currentName].raceAttributes[strIndex] = Int32.Parse(racesNode[i]["MODIFIERS"]["STR"].InnerText);
                    theCatalog.racesD[currentName].raceAttributes[dexIndex] = Int32.Parse(racesNode[i]["MODIFIERS"]["DEX"].InnerText);
                    theCatalog.racesD[currentName].raceAttributes[conIndex] = Int32.Parse(racesNode[i]["MODIFIERS"]["CON"].InnerText);
                    theCatalog.racesD[currentName].raceAttributes[intIndex] = Int32.Parse(racesNode[i]["MODIFIERS"]["INT"].InnerText);
                    theCatalog.racesD[currentName].raceAttributes[wisIndex] = Int32.Parse(racesNode[i]["MODIFIERS"]["WIS"].InnerText);
                    theCatalog.racesD[currentName].raceAttributes[charIndex] = Int32.Parse(racesNode[i]["MODIFIERS"]["CHAR"].InnerText);

                    theCatalog.racesD[currentName].raceAnyAttribute = false;
                }
                else if (racesNode[i]["MODIFIERS"].Attributes["any"].Value.Equals("true"))
                {

                    theCatalog.racesD[currentName].raceAnyAttribute = true;
                }

                racesCB.Items.Add(theCatalog.racesD[currentName].raceName);
            }
        }

        private void createClasses(XmlNodeList classesNode, XmlNodeList classesBaseAttack)
        {
            
            for (int i = 0; i < classesNode.Count; i++)
            {
                string currClass = classesNode[i]["NAME"].InnerText;
                

                theCatalog.addNewClass(currClass);

                theCatalog.classesD[currClass].className = currClass;
                classesCB.Items.Add(currClass);
                theCatalog.classesD[currClass].classRole = classesNode[i]["ROLE"].InnerText;
                theCatalog.classesD[currClass].classHitDie = classesNode[i]["HITDIE"].InnerText;
                theCatalog.classesD[currClass].classAlignment = classesNode[i]["ALIGNMENT"].InnerText;
                theCatalog.classesD[currClass].classSkillRank = Int32.Parse(classesNode[i]["SKILLRANK"].Attributes[0].InnerText);
                theCatalog.classesD[currClass].classSkillRankString = classesNode[i]["SKILLRANK"].InnerText;

                int skillCount = Int32.Parse(classesNode[i]["SKILLS"].Attributes[0].InnerText);

                string baseAttackType = classesNode[i]["LEVELS"].Attributes[0].InnerText;

                for (int j = 0; j < 20; j++)
                {
                    theCatalog.classesD[currClass].createClassDictionary(levelString[j], Int32.Parse(classesBaseAttack[0][baseAttackType][levelString[j]].Attributes[0].InnerText), Int32.Parse(classesNode[i]["LEVELS"][levelString[j]].Attributes[0].InnerText));
                    
                    theCatalog.classesD[currClass].classSaves[levelString[j]][fortSaveIndex] = Int32.Parse(classesNode[i]["LEVELS"][levelString[j]]["FORTSAVE"].InnerText);
                    theCatalog.classesD[currClass].classSaves[levelString[j]][refSaveIndex] = Int32.Parse(classesNode[i]["LEVELS"][levelString[j]]["REFSAVE"].InnerText);
                    theCatalog.classesD[currClass].classSaves[levelString[j]][willSaveIndex] = Int32.Parse(classesNode[i]["LEVELS"][levelString[j]]["WILLSAVE"].InnerText);
                    for (int k = 0; k < Int32.Parse(classesBaseAttack[0][baseAttackType][levelString[j]].Attributes[0].InnerText); k++)
                    {
                        theCatalog.classesD[currClass].classBaseAttack[levelString[j]][k] = classesBaseAttack[0][baseAttackType][levelString[j]][("BASEATTACK"+(k+1)).ToString()].InnerText;
                    }

                    for (int z = 0; z < Int32.Parse(classesNode[i]["LEVELS"][levelString[j]].Attributes[0].InnerText); z++)
                    {
                        if (classesNode[i]["LEVELS"][levelString[j]][("SPECIAL" + (z + 1)).ToString()].Attributes.Count != 0)
                        {
                            theCatalog.classesD[currClass].classSpecials[levelString[j]][z] = classesNode[i]["LEVELS"][levelString[j]][("SPECIAL" + (z + 1)).ToString()].Attributes[0].InnerText + " " + classesNode[i]["LEVELS"][levelString[j]][("SPECIAL" + (z + 1)).ToString()].InnerText;
                        }
                        else
                            theCatalog.classesD[currClass].classSpecials[levelString[j]][z] = classesNode[i]["LEVELS"][levelString[j]][("SPECIAL" + (z + 1)).ToString()].InnerText;
                    }
                    
                }
                    
                    for (int j = 0; j < skillCount-1; j++)
                    {
                        theCatalog.classesD[currClass].classSkills.Add(classesNode[i]["SKILLS"]["SKILL"+((j+1).ToString())].InnerText);
                    }

            }
        }

        private void createSpells(XmlNodeList spellNode)
        {
            for(int i = 0; i < spellNode.Count; i++)
            {
                string currSpell = spellNode[i]["NAME"].InnerText;
                theCatalog.addNewSpell(currSpell);

                theCatalog.spellsD[currSpell].name = currSpell;

                theCatalog.spellsD[currSpell].school = spellNode[i]["SCHOOL"].InnerText;
                theCatalog.spellsD[currSpell].level = spellNode[i]["LEVEL"].InnerText;
                theCatalog.spellsD[currSpell].castingtime = spellNode[i]["CASTINGTIME"].InnerText;
                theCatalog.spellsD[currSpell].components = spellNode[i]["COMPONENTS"].InnerText;
                theCatalog.spellsD[currSpell].area = spellNode[i]["AREA"].InnerText;
                theCatalog.spellsD[currSpell].target = spellNode[i]["TARGET"].InnerText;
                theCatalog.spellsD[currSpell].range = spellNode[i]["RANGE"].InnerText;
                theCatalog.spellsD[currSpell].effect = spellNode[i]["EFFECT"].InnerText;
                theCatalog.spellsD[currSpell].duration = spellNode[i]["DURATION"].InnerText;
                theCatalog.spellsD[currSpell].savingthrow = spellNode[i]["SAVINGTHROW"].InnerText;
                theCatalog.spellsD[currSpell].spellresistance = spellNode[i]["SPELLRESISTANCE"].InnerText;
                theCatalog.spellsD[currSpell].description = spellNode[i]["DESCRIPTION"].InnerText;

                TreeNode tn = new TreeNode(currSpell);
                tvSpells.Nodes.Add(tn);

            }
        }

        private void createFeats(XmlNodeList featNode)
        {
            for (int i = 0; i < featNode.Count; i++)
            {
                string currFeat = featNode[i]["NAME"].InnerText;
                theCatalog.addNewFeat(currFeat);

                theCatalog.featsD[currFeat].name = currFeat;
                theCatalog.featsD[currFeat].prereq = featNode[i]["PREREQ"].InnerText;
                theCatalog.featsD[currFeat].benefits = featNode[i]["BENEFITS"].InnerText;

                TreeNode tn = new TreeNode(currFeat);
                tvFeats.Nodes.Add(tn);

            }
        }

        private void classesCB_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox tempCMB = (ComboBox)sender;

            string currentClassName;

            SkillDGV.Rows.Clear();

            if (tempCMB.Text != null)
                currentClassName = tempCMB.Text;
            else
                return;

            lblClassesOV.Text = "Class : " + currentClassName;

            roleTB.Text = theCatalog.classesD[currentClassName].classRole;
            skillsPerLvlLB.Text = "Skills Per Lvl : " + theCatalog.classesD[currentClassName].classSkillRankString; //add the int modifier for the OV
            alignmentClassLB.Text = "Alignment : " + theCatalog.classesD[currentClassName].classAlignment;
            hitDieLB.Text = "Hit Die : " + theCatalog.classesD[currentClassName].classHitDie;


            lgBT.Enabled = lnBT.Enabled = leBT.Enabled = true;
            ngBT.Enabled = tnBT.Enabled = neBT.Enabled = true;
            cgBT.Enabled = cnBT.Enabled = ceBT.Enabled = true;

            
            if (theCatalog.classesD[currentClassName].classAlignment == "Any lawful") //possible change might list in xml for easiness adding new classes.
            {
                ngBT.Enabled = tnBT.Enabled = neBT.Enabled = false;
                cgBT.Enabled = cnBT.Enabled = ceBT.Enabled = false;
            }
            else if (theCatalog.classesD[currentClassName].classAlignment == "Lawful good")
            {
                lnBT.Enabled = leBT.Enabled = false;
                ngBT.Enabled = tnBT.Enabled = neBT.Enabled = false;
                cgBT.Enabled = cnBT.Enabled = ceBT.Enabled = false;
            }
            else if (theCatalog.classesD[currentClassName].classAlignment == "Any nonlawful")
            {
                lgBT.Enabled = lnBT.Enabled = leBT.Enabled = false;
            }
            else if (theCatalog.classesD[currentClassName].classAlignment == "Any neutral")
            {
                lgBT.Enabled = lnBT.Enabled = leBT.Enabled = false;
                cgBT.Enabled = cnBT.Enabled = ceBT.Enabled = false;
            }

            for (int j = 0; j < theCatalog.classesD[currentClassName].classSkills.Count - 1; j++)
            {
                SkillDGV.Rows.Add(theCatalog.classesD[currentClassName].classSkills[j],"0");
                lblSkillRank.Text = theCatalog.classesD[currentClassName].classSkillRank.ToString();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                ClassTable cT = new ClassTable(theCatalog.classesD[classesCB.Text].classBaseAttack, theCatalog.classesD[classesCB.Text].classSaves, theCatalog.classesD[classesCB.Text].classSpecials);
                cT.Show();
            }
            catch (Exception) { }

            
        }

        private void strNumUD_ValueChanged(object sender, EventArgs e)
        {

            if (Int32.Parse(strOVLB.Text) < strNumUD.Value)
            {
                if (!incrementedValue((int)strNumUD.Value))
                {
                    strNumUD.Value -= 1;
                    return;
                }
            }
            else if (Int32.Parse(strOVLB.Text) > strNumUD.Value)
                decrementedValue((int)strNumUD.Value);


            strOVLB.Text = strNumUD.Value.ToString();
            int temp = (int)((strNumUD.Value - 10)/2);
            if (temp >= 0)
                lblStrMod.Text = lblStrModOV.Text = "+" + temp.ToString();
            else
                lblStrMod.Text = lblStrModOV.Text = temp.ToString();


         }

        private void dexNumUD_ValueChanged(object sender, EventArgs e)
        {
            if (Int32.Parse(dexOVLB.Text) < dexNumUD.Value)
            {
                if (!incrementedValue((int)dexNumUD.Value))
                {
                    dexNumUD.Value -= 1;
                    return;
                }
            }
            else if (Int32.Parse(dexOVLB.Text) > dexNumUD.Value)
                decrementedValue((int)dexNumUD.Value);

            dexOVLB.Text = dexNumUD.Value.ToString();
            int temp = (int)((dexNumUD.Value - 10) / 2);
            if (temp >= 0)
                lblDexMod.Text = lblDexModOV.Text = "+" + temp.ToString();
            else
                lblDexMod.Text = lblDexModOV.Text = temp.ToString();
        }

        private void conNumUD_ValueChanged(object sender, EventArgs e)
        {

            if (Int32.Parse(conOVLB.Text) < conNumUD.Value)
            {
                if (!incrementedValue((int)conNumUD.Value))
                {
                    conNumUD.Value -= 1;
                    return;
                }
            }
            else if (Int32.Parse(conOVLB.Text) > conNumUD.Value)
                decrementedValue((int)conNumUD.Value);

            conOVLB.Text = conNumUD.Value.ToString();
            int temp = (int)((conNumUD.Value - 10)/2);
            if (temp >= 0)
                lblConMod.Text = lblConModOV.Text = "+" + temp.ToString();
            else
                lblConMod.Text = lblConModOV.Text = temp.ToString();
        }

        private void intNumUD_ValueChanged(object sender, EventArgs e)
        {

            if (Int32.Parse(intOVLB.Text) < intNumUD.Value)
            {
                if (!incrementedValue((int)intNumUD.Value))
                {
                    intNumUD.Value -= 1;
                    return;
                }
            }
            else if (Int32.Parse(intOVLB.Text) > intNumUD.Value)
                decrementedValue((int)intNumUD.Value);

            intOVLB.Text = intNumUD.Value.ToString();
            int temp = (int)((intNumUD.Value - 10) / 2);
            if (temp >= 0)
                lblIntMod.Text = lblIntModOV.Text = "+" + temp.ToString();
            else
                lblIntMod.Text = lblIntModOV.Text = temp.ToString();

            int classSkillRankTemp = 0;

            if (classesCB.Text == null || classesCB.Text == "")
                classSkillRankTemp = Int32.Parse(lblIntMod.Text);
            else
                classSkillRankTemp = theCatalog.classesD[classesCB.Text].classSkillRank + Int32.Parse(lblIntMod.Text);

            lblSkillRank.Text = classSkillRankTemp.ToString();
        }

        private void wisNumUD_ValueChanged(object sender, EventArgs e)
        {
            if (Int32.Parse(wisOVLB.Text) < wisNumUD.Value)
            {
                if (!incrementedValue((int)wisNumUD.Value))
                {
                    wisNumUD.Value -= 1;
                    return;
                }
            }
            else if (Int32.Parse(wisOVLB.Text) > wisNumUD.Value)
                decrementedValue((int)wisNumUD.Value);

            wisOVLB.Text = wisNumUD.Value.ToString();
            int temp = (int)((wisNumUD.Value - 10) / 2);
            if (temp >= 0)
                lblWisMod.Text = lblWisModOV.Text = "+" + temp.ToString();
            else
                lblWisMod.Text = lblWisModOV.Text = temp.ToString();
        }

        private void charNumUD_ValueChanged(object sender, EventArgs e)
        {
            if (Int32.Parse(charOVLB.Text) < charNumUD.Value)
            {
                if (!incrementedValue((int)charNumUD.Value))
                {
                    charNumUD.Value -= 1;
                    return;
                }
            }
            else if (Int32.Parse(charOVLB.Text) > charNumUD.Value)
                decrementedValue((int)charNumUD.Value);

            charOVLB.Text = charNumUD.Value.ToString();
            int temp = (int)((charNumUD.Value - 10) / 2);
            if (temp >= 0)
                lblCharMod.Text = lblCharModOV.Text = "+" + temp.ToString();
            else
                lblCharMod.Text = lblCharModOV.Text = temp.ToString();
        }

        private bool incrementedValue(int num)
        {
            int cost = 0;
            switch (num)
            {
                case 8:
                    //lblPointsLeftNum.Text = (Int32.Parse(lblPointsLeftNum.Text) - 2).ToString();
                    cost = 2;
                    break;
                case 9:
                    //lblPointsLeftNum.Text = (Int32.Parse(lblPointsLeftNum.Text) - 1).ToString();
                    cost = 1;
                    break;
                case 10:
                    //lblPointsLeftNum.Text = (Int32.Parse(lblPointsLeftNum.Text) - 1).ToString();
                    cost = 1;
                    break;
                case 11:
                     //lblPointsLeftNum.Text = (Int32.Parse(lblPointsLeftNum.Text) - 1).ToString();
                     cost = 1;
                    break;
                case 12:
                    //lblPointsLeftNum.Text = (Int32.Parse(lblPointsLeftNum.Text) - 1).ToString();
                    cost = 1;
                    break;
                case 13:
                     //lblPointsLeftNum.Text = (Int32.Parse(lblPointsLeftNum.Text) -1).ToString();
                     cost = 1;
                    break;
                case 14:
                     //lblPointsLeftNum.Text = (Int32.Parse(lblPointsLeftNum.Text) - 2).ToString();
                     cost = 2;
                    break;
                case 15:
                     //lblPointsLeftNum.Text = (Int32.Parse(lblPointsLeftNum.Text) - 2).ToString();
                     cost = 2;
                    break;
                case 16:
                    //lblPointsLeftNum.Text = (Int32.Parse(lblPointsLeftNum.Text) - 3).ToString();
                    cost = 3;
                    break;
                case 17:
                    //lblPointsLeftNum.Text = (Int32.Parse(lblPointsLeftNum.Text) - 3).ToString();
                    cost = 3;
                    break;
                case 18:
                    //lblPointsLeftNum.Text = (Int32.Parse(lblPointsLeftNum.Text) - 4).ToString();
                    cost = 4;
                    break;
            }
            if (Int32.Parse(lblPointsLeftNum.Text) - cost > 0)
            {
                lblPointsLeftNum.Text = (Int32.Parse(lblPointsLeftNum.Text) - cost).ToString();
                return true;
            }
            return false;
        }

        private void decrementedValue(int num)
        {
            switch (num)
            {
                case 7:
                    lblPointsLeftNum.Text = (Int32.Parse(lblPointsLeftNum.Text) + 2).ToString();
                    break;
                case 8:
                    lblPointsLeftNum.Text = (Int32.Parse(lblPointsLeftNum.Text) + 1).ToString();
                    break;
                case 9:
                    lblPointsLeftNum.Text = (Int32.Parse(lblPointsLeftNum.Text) + 1).ToString();
                    break;
                case 10:
                    lblPointsLeftNum.Text = (Int32.Parse(lblPointsLeftNum.Text) + 1).ToString();
                    break;
                case 11:
                    lblPointsLeftNum.Text = (Int32.Parse(lblPointsLeftNum.Text) + 1).ToString();
                    break;
                case 12:
                    lblPointsLeftNum.Text = (Int32.Parse(lblPointsLeftNum.Text) + 1).ToString();
                    break;
                case 13:
                    lblPointsLeftNum.Text = (Int32.Parse(lblPointsLeftNum.Text) + 2).ToString();
                    break;
                case 14:
                    lblPointsLeftNum.Text = (Int32.Parse(lblPointsLeftNum.Text) + 2).ToString();
                    break;
                case 15:
                    lblPointsLeftNum.Text = (Int32.Parse(lblPointsLeftNum.Text) + 3).ToString();
                    break;
                case 16:
                    lblPointsLeftNum.Text = (Int32.Parse(lblPointsLeftNum.Text) + 3).ToString();
                    break;
                case 17:
                    lblPointsLeftNum.Text = (Int32.Parse(lblPointsLeftNum.Text) + 4).ToString();
                    break;
            }
        }

        private void cbPointFantasy_SelectedIndexChanged(object sender, EventArgs e)
        {
            strNumUD.Value = 10;
            dexNumUD.Value = 10;
            conNumUD.Value = 10;
            intNumUD.Value = 10;
            wisNumUD.Value = 10;
            charNumUD.Value = 10;

            ComboBox tempCMB = (ComboBox)sender;

            if (tempCMB.SelectedIndex == 0)
            {
                lblPointsFantasy.Text = "Points: 10";
                lblPointsLeftNum.Text = (10).ToString();
            }
            else if (tempCMB.SelectedIndex == 1)
            {
                lblPointsFantasy.Text = "Points: 15";
                lblPointsLeftNum.Text = (15).ToString();
            }
            else if (tempCMB.SelectedIndex == 2)
            {
                lblPointsFantasy.Text = "Points: 20";
                lblPointsLeftNum.Text = (20).ToString();
            }
            else if (tempCMB.SelectedIndex == 3)
            {
                lblPointsFantasy.Text = "Points: 25";
                lblPointsLeftNum.Text = (25).ToString();
            }
        }

        private void SkillDGV_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            Int32 counter = 0;

            foreach (DataGridViewRow dr in SkillDGV.Rows)
            {
                if(dr.Cells["SkillValue"].Value != null)
                    counter += Int32.Parse(dr.Cells["SkillValue"].Value.ToString());
            }

            lblSkillRank.Text = (theCatalog.classesD[classesCB.Text].classSkillRank - counter).ToString();
        
        }

        private void lgBT_Click(object sender, EventArgs e)
        {
            lblAlignmentOV.Text = "Lawful Good";
        }

        private void ngBT_Click(object sender, EventArgs e)
        {
            lblAlignmentOV.Text = "Neutral Good";
        }

        private void cgBT_Click(object sender, EventArgs e)
        {
            lblAlignmentOV.Text = "Chaotic Good";
        }

        private void lnBT_Click(object sender, EventArgs e)
        {
            lblAlignmentOV.Text = "Lawful Neutral";
        }

        private void tnBT_Click(object sender, EventArgs e)
        {
            lblAlignmentOV.Text = "True Neutral";
        }

        private void cnBT_Click(object sender, EventArgs e)
        {
            lblAlignmentOV.Text = "Chaotic Neutral";
        }

        private void leBT_Click(object sender, EventArgs e)
        {
            lblAlignmentOV.Text = "Lawful Evil";
        }

        private void neBT_Click(object sender, EventArgs e)
        {
            lblAlignmentOV.Text = "Neutral Evil";
        }

        private void ceBT_Click(object sender, EventArgs e)
        {
            lblAlignmentOV.Text = "Chaotic Evil";
        }

        private void tvFeats_AfterSelect(object sender, TreeViewEventArgs e)
        {
            lblFeatName.Text = "Name : " + tvFeats.SelectedNode.Text;

            lblFeatBenefits.Text = "Benefits : " + theCatalog.featsD[tvFeats.SelectedNode.Text].benefits;
            lblFeatPrereq.Text = "Prereq : " + theCatalog.featsD[tvFeats.SelectedNode.Text].prereq;

        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {

                tvSelectedFeats.Nodes.Add(tvFeats.SelectedNode.Text);
                tvFeats.SelectedNode.Remove();
            }
            catch (Exception) { }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                tvFeats.Nodes.Add(tvSelectedFeats.SelectedNode.Text);
                tvSelectedFeats.SelectedNode.Remove();
                tvFeats.Sort();
            }
            catch (Exception) { }
            
        }

        private void tvSpells_AfterSelect(object sender, TreeViewEventArgs e)
        {
            string currSpell = tvSpells.SelectedNode.Text;

            lblSpellName.Text = "Name : " + currSpell;
            lblSpellSchool.Text = "School : " + theCatalog.spellsD[currSpell].school;
            lblSpellRange.Text = "Range : " + theCatalog.spellsD[currSpell].range;
            lblSpellResistance.Text = "Spell Resistance : " + theCatalog.spellsD[currSpell].spellresistance;
            lblSpellSavingThrow.Text = "Saving Throw : " + theCatalog.spellsD[currSpell].savingthrow;
            lblSpellTarget.Text = "Target : " + theCatalog.spellsD[currSpell].target;
            lblSpellEffect.Text = "Effect : " + theCatalog.spellsD[currSpell].effect;
            lblSpellCastingTime.Text = "Casting Time : " + theCatalog.spellsD[currSpell].castingtime;
            lblSpellComponenets.Text = "Componenets : " + theCatalog.spellsD[currSpell].components;
            lblSpellArea.Text = "Area : " + theCatalog.spellsD[currSpell].area;
            lblSpellDescription.Text = "Description : " + theCatalog.spellsD[currSpell].description;
            lblSpellDuration.Text = "Duration : " + theCatalog.spellsD[currSpell].duration;
        }







    }
}
